<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Business_group extends Model
{
    //
	protected $table='business_group';
	protected $fillable=['name','department_id','leader','leader_name','company_id'];
	protected $hidden=[];
	public function allgroupData($where){
		return $this->where(function ($query) use($where){
			if($where['name'] !=null){
				$query->where('name','like','%'.$where['name'].'%');
			}
			if($where['start_time'] !=null){
				$query->where('created_at','>',$where['start_time']);
			}
			if($where['end_time'] !=null){
				$query->where('created_at','<',$where['end_time']);

			}
			if($where['leader_name'] !=null){
				$query->where('leader_name','like','%'.$where['leader_name'].'%');
			}

		})->with('userinfo')->paginate(config('app.config'));
	}

	public function userinfo(){
		return $this->belongsTo('App\Model\Users','leader');
	}

//	业务组详情
	public function desc($id){
		return $this->where(['id'=>$id])->with('member')->with('departments')->first();
	}

//	业务组成员
	public function member(){
		return $this->hasMany('App\Model\Group_member','group_id');
	}

	public function departments(){
		return $this->belongsTo('App\Model\Department','department_id');
	}




}
